@model IEnumerable<Von.Web.Models.ApplicationModel>
@{
    ViewData["Title"] = "模块信息管理";
}
<h2>应用信息管理<a class="btn btn-link" onclick="NewApplication()">注册应用</a></h2>
<table id="ApplicationList" class="table">
    <thead>
        <tr>
            <th>@Html.DisplayNameFor(model => model.AppName)</th>
            <th>@Html.DisplayNameFor(model => model.AppTitle)</th>
            <th>@Html.DisplayNameFor(model => model.AssemlyName)</th>
            <th>@Html.DisplayNameFor(model => model.Prefix)</th>
            <th>@Html.DisplayNameFor(model => model.Owner)</th>
            <th>@Html.DisplayNameFor(model => model.Qualifier)</th>
            <th>@Html.DisplayNameFor(model => model.WorkPath)</th>
            <th>@Html.DisplayNameFor(model => model.LogClass)</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
        <tr>
            <td>@Html.DisplayFor(modelItem => item.AppName)</td>
            <td>@Html.DisplayFor(modelItem => item.AppTitle)</td>
            <td>@Html.DisplayFor(modelItem => item.AssemlyName)</td>
            <td>@Html.DisplayFor(modelItem => item.Prefix)</td>
            <td>@Html.DisplayFor(modelItem => item.Owner)</td>
            <td>@Html.DisplayFor(modelItem => item.Qualifier)</td>
            <td>@Html.DisplayFor(modelItem => item.WorkPath)</td>
            <td>@Html.DisplayFor(modelItem => item.LogClass)</td>
            <td>
                <input type="button" class="btn-link" onclick="EditApplication(this,'@item.ID')" value="编辑">
                <input type="button" class="btn-link" onclick="DeleteApplication(this,'@item.ID')" value="删除">
            </td>
        </tr>
        }
    </tbody>
</table>
<!-- 模态框（Modal） -->
<div class="modal fade" id="ApplicationEditor" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true" data-mode="new">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="background-color:aquamarine;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="ModalLabel">应用信息编辑</h4>
                <input id="flag" type="hidden" />
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="ID" class="control-label">@Html.DisplayNameFor(model => model.ID)</label>
                    <input id="ID" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="AppName" class="control-label">@Html.DisplayNameFor(model => model.AppName)</label>
                    <input id="AppName" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="AppTitle" class="control-label">@Html.DisplayNameFor(model => model.AppTitle)</label>
                    <input id="AppTitle" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="AssemlyName" class="control-label">@Html.DisplayNameFor(model => model.AssemlyName)</label>
                    <input id="AssemlyName" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="Prefix" class="control-label">@Html.DisplayNameFor(model => model.Prefix)</label>
                    <input id="Prefix" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="Owner" class="control-label">@Html.DisplayNameFor(model => model.Owner)</label>
                    <input id="Owner" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="Qualifier" class="control-label">@Html.DisplayNameFor(model => model.Qualifier)</label>
                    <input id="Qualifier" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="WorkPath" class="control-label">@Html.DisplayNameFor(model => model.WorkPath)</label>
                    <input id="WorkPath" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="LogClass" class="control-label">@Html.DisplayNameFor(model => model.LogClass)</label>
                    <select id="LogClass" class="form-control">
                        <option value="0" selected>跟踪测试</option>
                        <option value="1">记录信息</option>
                        <option value="2">警告信息</option>
                        <option value="3">异常错误</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="Cert" class="control-label">模块证书</label>
                    <textarea id="Cert" class="form-control"></textarea>
                </div>
                <div class="form-group">
                    <label for="Settings" class="control-label">设置</label>
                    <textarea id="Settings" class="form-control"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <div class="form-group">
                    <input value="保存" class="btn btn-default" onclick="SaveApplication()" />
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<script type="text/javascript">
    function NewApplication() {
        von.selectRow();
        $("#ID").removeAttr("disabled");
        von.editor.clear();
        von.editor.display("reg");
    }
    function EditApplication(btn, id) {
        von.selectRow(btn);
        $("#ID").attr("disabled", true);
        AjaxPostData("@Url.Ajax("GetApplication")", { ID: id }, function (data) {
            if (data != null) von.editor.setData(data);
            $("#Settings").val(JSON.stringify(data.AppSetting, null, 4));
            von.editor.display("edit");
        });
    }
    function CheckData() {
        if ($('#AppName').val() == "") return "@Html.Raw(Html.DisplayNameFor(model => model.AppName))不能为空！";
        if ($('#AppTitle').val() == "") return "@Html.Raw(Html.DisplayNameFor(model => model.AppTitle))不能为空！";
        if ($('#AssemlyName').val() == "") return "@Html.Raw(Html.DisplayNameFor(model => model.AssemlyName))不能为空！";
        if ($('#Prefix').val() == "") return "@Html.Raw(Html.DisplayNameFor(model => model.Prefix))不能为空！";
        if ($('#Owner').val() == "") return "@Html.Raw(Html.DisplayNameFor(model => model.Owner))不能为空！";
        if ($('#Qualifier').val() == "") return "@Html.Raw(Html.DisplayNameFor(model => model.Qualifier))不能为空！";
        return "";
    }
    function SaveApplication() {
        var msg = CheckData();
        if (msg != "") return SysWarning(msg);
        var data = {};
        von.editor.getData(data);
        data.AppSetting = $("#Settings").val();
        AjaxPostData("@Url.Ajax("SaveApplication")", data, function (data) { von.replaceRow(von.getHtml(data)); von.editor.close(); });
    }
</script>

@Html.Import(EImportSection.BodyTrailler, "ModuleManage",
    @<script>
        var von = VonGrid({
            app: "Application",
            keyName: "ID",
            displayFields: ["AppName", "AppTitle", "AssemlyName", "Prefix", "Owner", "Qualifier", "WorkPath", "LogClass"],
            fields: ["ID", "AppName", "AppTitle", "AssemlyName", "Prefix", "Owner", "Qualifier","WorkPath","LogClass", "Cert"]
        });
    </script>
)